<?php
namespace App\Http\Controllers\AdminApi;
use App\Model\WordTable;
use App\Model\JoinTable;
use App\Repository\Admin\AdminService;
use App\Repository\BaseController\ApiController;
use App\Repository\Common\ConstTable;
use App\Repository\Sys\JsonRespose;
use App\Repository\Sys\Str;
//简历管理
class WordController extends ApiController{
	//简历-列表
    public function getWordList(){
        $page = \Request::get('page', 1);
        $limit = \Request::get('page_num', 10);
        $title = \Request::get('title');
        $offset = ($page - 1) * $limit;
        //拼接sql
        $where = "1=1 and d.status>0";
        $parameters = array(
            'limit' => $limit,
            'offset' => $offset
        );
        if ($title) {
            $where .= " AND  d.name LIKE :name ";
            $parameters['name'] = $title;
        }
        $sql = "select * from word as d  WHERE {$where} ORDER BY d.id DESC limit  :offset,:limit;";
        //执行sql
        $res = \DB::select($sql, $parameters);
        unset($parameters['limit'], $parameters['offset']);
        $count = \DB::select("select count(*) as c from word as d WHERE {$where}", $parameters)[0]->c;
        $data=[];
        foreach ($res as $v) {
        	$join_id=$v->join_id;
        	$join = $db = JoinTable::ORM()->where('id', $join_id)->first();
        	$v->join_name = $join->title;
        	$v->created_at = Str::dateFormat('Y-m-d', $v->created_at);
        	$v->status_text=ConstTable::WORD_STATUS_NAME[$v->status];
        	$data[] = $v;
        }
        return JsonRespose::success([
            'count' => $count,
            'limit' => $limit,
            'page' => $page,
            'res' => $data
        ]);
    }
    //简历-状态修改
    public function postWordStatus(){
        $id = \Request::get('id');
        $status = \Request::get('status');
        //取得当前数据
        $res = WordTable::ORM()->where('id', $id)->update(['status' => $status]);
        if ($res) {
            return JsonRespose::success();
        } else {
            return JsonRespose::fail();
        }
    }
}


